//
//  OperationBillDetailRejectCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/11/10.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "OperationBillDetailRejectCell.h"

@interface OperationBillDetailRejectCell ()

@property (nonatomic, strong) UIView *bgView;

@end

@implementation OperationBillDetailRejectCell

+ (instancetype)OperationBillDetailRejectCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"OperationBillDetailRejectCell";
    OperationBillDetailRejectCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[OperationBillDetailRejectCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
    }
    return self;
}

-(void)setModel:(OperationBillDetailModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 10;
    self.bgView.nim_width = ScreenW - 30;
    
    [self.bgView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    __block CGFloat pickTop = 10;
    [self.model.d_reject_list enumerateObjectsUsingBlock:^(OperationBillRejectModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        OperationBillDetailRejectView *view = [[OperationBillDetailRejectView alloc] initWithFrame:CGRectMake(15, pickTop, self.bgView.nim_width - 30, 0)];
        view.model = obj;
        view.nim_height = view.height;
        if (idx == self.model.d_reject_list.count - 1) {
            view.dismissLine = YES;
        }
        [self.bgView addSubview:view];
        pickTop = view.nim_bottom;
    }];
    
    self.bgView.nim_height = pickTop + 10;
    self.height = self.bgView.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

@interface OperationBillDetailRejectView (){
    CGFloat viewW;
}

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UILabel *contentLab;
@property (nonatomic, strong) UILabel *line;

@end

@implementation OperationBillDetailRejectView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = HexColor(0xffffff);
        viewW = frame.size.width;
        
        self.titleLab = [UILabel new];
        self.titleLab.textColor = HexColor(0xF35959);
        self.titleLab.font = BoldFontOfSize(18);
        [self addSubview:self.titleLab];
        
        self.timeLab = [UILabel new];
        self.timeLab.textColor = HexColor(0x585974);
        self.timeLab.font = [UIFont systemFontOfSize:12];
        [self addSubview:self.timeLab];
        
        self.contentLab = [UILabel new];
        self.contentLab.textColor = HexColor(0x585974);
        self.contentLab.font = [UIFont systemFontOfSize:12];
        self.contentLab.numberOfLines = 0;
        [self addSubview:self.contentLab];
        
        self.line = [UILabel new];
        self.line.backgroundColor = Color_backgroundColor;
        [self addSubview:self.line];
    }
    return self;
}

-(void)setModel:(OperationBillRejectModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.titleLab.text = [NSString stringWithFormat:@"操作单被%@司机驳回了！",self.model.name];
    self.titleLab.nim_left = 0;
    self.titleLab.nim_top = 10;
    [self.titleLab sizeToFit];
    
    self.timeLab.text = self.model.reject_time;
    self.timeLab.nim_left = self.titleLab.nim_left;
    self.timeLab.nim_top = self.titleLab.nim_bottom + 3;
    [self.timeLab sizeToFit];
    
    self.contentLab.text = self.model.reject;
    self.contentLab.nim_left = self.timeLab.nim_left;
    self.contentLab.nim_top = self.timeLab.nim_bottom + 10;
    self.contentLab.nim_width = viewW;
    [self.contentLab sizeToFit];
    self.contentLab.nim_width = viewW;
    
    self.line.frame = CGRectMake(self.titleLab.nim_left, self.contentLab.nim_bottom + 15, viewW, 1);
    self.height = self.line.nim_bottom;
}

-(void)setDismissLine:(BOOL)dismissLine {
    _dismissLine = dismissLine;
    self.line.hidden = dismissLine;
}

@end
